package camelinaction;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.DispatcherServlet;

import java.util.HashMap;
import java.util.Map;

/**
 * A Camel route in Spring Boot.
 *
 * Notice that we use @Component on the class to make the route automatic discovered by Spring Boot
 */


@Component
public class HelloRoute extends RouteBuilder{

    // see the application.properties file how we map the context-path
    // of the camel-servlet that the rest-dsl will use

    @Override
    public void configure() throws Exception {
        // define a Camel REST service using the rest-dsl
        // where we define a GET /hello as a service that routes to the hello route
        // we will cover rest-dsl in chapter 10

/*        rest("/").produces("text/plain")
            .get("hello")
            .to("direct:hello");

        from("direct:hello")
            //.to("geocoder:address:current")
            .transform().simple("Hello from Spring Boot and Camel. We are at: ${body}");*/
//https://blog.csdn.net/fengchen0123456789/article/details/76208940
       /* from("netty4:tcp://localhost:10102?decoders=#decoderFactory")
                .process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception {
                        System.out.println(exchange.toString());
                    }
                });*/
        from("netty4:tcp://localhost:10102?serverInitializerFactory=#sampleServerInitializerFactory")
                .process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception {
                        System.out.println(exchange.toString());
                    }
                });
                //.to("geocoder:address:current")
                //.transform().simple("Hello from Spring Boot and Camel. We are at:Netty");


        //问题：启动的时候，为什么会启动camelservlet
        //用nettyIOT的客户端，已经能够执行捕捉到Exchange
        //pipeline如何加载
        //session如何进行保留？
        //如果发回？

    }
}
